/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var subarraySum = function (nums, k) {
  //1. 获取 前缀和
  let _preSum = []
  nums.reduce((sum, cur) => {
    let res = sum + cur
    _preSum.push(res)
    return res
  }, 0)
  console.log(_preSum)

  //2. 获取中间和为k的数字
  let count = 0
  for (let i = 0; i < _preSum.length; i++) {
    for (let j = 0; j <= i; j++) {
      console.log(i, j)
      let res = _preSum[i] - _preSum[j] + nums[j]
      console.log('pre_i', _preSum[i], 'pre_j', _preSum[j] - nums[j], 'res:\t' + res)
      if (res === k) count++
    }
  }
  return count
}

console.log('Sub res:\t' + subarraySum([1, 2, 3], 3))
